#pragma once
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/epoll.h>
#define EPOLL_CREATE_SIZE 10
class Epoll 
{
public:
    Epoll()
    {
        _epfd = epoll_create(EPOLL_CREATE_SIZE);
        if(_epfd < 0)
        {
            std::cout << "epoll_create fail:" << strerror(errno) << errno << std::endl;
            exit(6);
        }
    }
    void Epoll_Ctl(int op, int sock, int event)
    {
        epoll_event e;
        e.data.fd = sock;
        e.events = event;
        int ret = epoll_ctl(_epfd, op, sock, &e);
        if(ret < 0)
        {
            std::cout << "epoll_ctl fail:" << strerror(errno) << errno << std::endl;
            exit(7);
        }
    }
    int Epoll_Wait(epoll_event* event, int maxevent, int timeout)
    {
        int n = epoll_wait(_epfd, event, maxevent, timeout);
        if(n < 0)
        {
            std::cout << "epoll_wait fail:" << strerror(errno) << errno << std::endl;
            exit(8);
        }
        return n;
    }
    ~Epoll()
    {
        if(_epfd > 0)
            close(_epfd);
    }

private:
    int _epfd;
};